<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/axios.js"></script>
</head>

<body>
    <script>
        //全局配置一个域名
        //axios.defaults.baseURL = "http://localhost:3000/"
        // axios拦截器
        // request 请求
        axios.interceptors.request.use(function (config) {
            console.log(config.url);  //请求的资源地址 http://localhost:3000/data
            console.log(config.headers);
            //如果登录成功之后设置一个token(令牌)
            //请求头中设置token
            config.headers.token = encodeURIComponent("好谷")
            return config;
        }, function (error) {
            return Promise.reject(error);
        });

        //response响应
        axios.interceptors.response.use(function (res) {
            // console.log(res.data);
            var data = res.data
            return data
        }, function (err) {
            console.log(err);
        })

        axios.get("http://localhost:3000/data").then(result => {
            console.log(result);
        })

        axios.get("http://localhost:3000/data1").then(result => {
            console.log(result);
        })
    </script>
</body>

</html>